package com.example.service.impl;

import com.example.config.cache.CacheDbTemplate;
import com.example.entity.pojo.Ordr;
import com.example.mapper.OrderMapper;
import com.example.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderCacheServiceImpl extends CacheDbTemplate<Ordr, OrderMapper, Long> implements OrderService {
    @Override
    protected String getDatabaseName() {
        return "demo";
    }

    @Override
    protected String getTableName() {
        return "ordr";
    }

    // --------------------------------------------------------------

    public Ordr getOrder(Long id) {
        return super.baseMapper.selectById(id);
    }

    @Transactional
    public void saveOrder(Ordr order) {
        super.baseMapper.insert(order);
    }

    @Transactional
    public void updateOrder(Ordr order) {
        super.baseMapper.updateById(order);
    }

    @Transactional
    public void deleteOrder(Long id) {
        super.baseMapper.deleteById(id);
    }


    // --------------------------------------------------------------


    public Ordr getOrderWithRedis(Long id) {
        return super.getById(id);
    }

    @Transactional
    public void saveOrderWithRedis(Ordr order) {
        super.save(order);
    }

    @Transactional
    public void updateOrderWithRedis(Ordr order) {
        super.updateById(order);
    }

    @Transactional
    public void deleteOrderWithRedis(Long id) {
        super.removeById(id);
    }
}
